﻿using System;
using System.Collections;
using System.Data;
using Model.Entity;

namespace DAL
{
    public class RfidDAL
    {
        private BaseDAL baseDal = null;
        private readonly static String CAN_BORROW_HQL = "select r from Rfid r inner join r.book where r not in(select b.rfid from Borrow b where b.isReturn=false) and r.canBorrow=true and r.rfid=?",            
            GET_SQL = "select * from _Rfid r inner join _Book b on r.bookIsbn = b.isbn inner join _Borrow bo on r.rfid=bo.rfid where bo.id=@0";

        public RfidDAL()
        {
            baseDal = new BaseDAL();
        }

        public Rfid canBorrow(String rfid)
        {
            foreach (Rfid result in baseDal.executeHql(CAN_BORROW_HQL, rfid))
            {
                return result;
            }
            return null;
        }        

        public DataTable getT(int borrowId)
        {
            return baseDal.executeSql(GET_SQL, borrowId);
        }
    }
}
